//
//  NSData+ReadableDescription.m
//  HessianKit
//
//  Copyright 2008-2009 Fredrik Olsson, Cocoway. All rights reserved.
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License. 
//  You may obtain a copy of the License at 
// 
//  http://www.apache.org/licenses/LICENSE-2.0 
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, 
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import "NSData+ReadableDescription.h"


@implementation NSData (ReadableDescription)

-(NSString*)description1;
{
	unsigned long length = [self length];
  NSMutableString* str = [NSMutableString stringWithFormat:@"[%zd]: ", length];
  const char* bytes = (const char*)[self bytes];
  for (int i = 0; i < length; i++) {
  	int byte = ((int)bytes[i]) & 0xff;
    if (byte >= 32 && byte <= 127) {
	    [str appendFormat:@"%02x:%c ", byte, (char)byte];
    } else {
	    [str appendFormat:@"%02x ", byte];
    }
  }
  return str;
}

@end
